package com.yfp.operation.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfp.operation.domain.OrderDetailDO;
import com.yfp.operation.domain.dto.OrderDetailDTO;
import com.yfp.operation.domain.vo.OrderDetailVO;
import com.yfp.operation.domain.vo.OrderInfoVO;
import com.yfp.operation.mapper.OrderDetailMapper;
import com.yfp.operation.service.OrderDetailService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 *
 * @description 针对表【order_detail】的数据库操作Service实现
 * @createDate 2024-04-19 16:44:44
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetailDO> implements OrderDetailService {

    @Resource
    private OrderDetailMapper orderDetailMapper;

    /**
     * 根据订单id获取订单详情
     *
     * @param orderId
     * @return
     */
    @Override
    public List<OrderInfoVO> getByOrderId(String orderId) {

        List<OrderInfoVO> list = orderDetailMapper.getByOrderId(orderId);
        return list;
    }

    /**
     * 根据订单id集合获取订单详情
     *
     * @param orderIds
     * @return
     */
    @Override
    public List<OrderDetailDO> listByOrderIds(List<String> orderIds) {
        LambdaQueryWrapper<OrderDetailDO> queryWrapper = Wrappers.lambdaQuery(OrderDetailDO.class).in(OrderDetailDO::getOrderId, orderIds);
        return this.list(queryWrapper);
    }

    /**
     * 根据订单详情id集合获取订单详情
     *
     * @param orderDetailIds
     * @return
     */
    @Override
    public List<OrderDetailDO> listByOrderDetailIds(List<String> orderDetailIds) {
        if (CollUtil.isEmpty(orderDetailIds)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<OrderDetailDO> queryWrapper = Wrappers.lambdaQuery(OrderDetailDO.class).in(OrderDetailDO::getOrderDetailId, orderDetailIds);
        return this.list(queryWrapper);
    }

    @Override
    public List<OrderDetailVO> getDetail(String orderSn) {
        return orderDetailMapper.getDetail(orderSn);
    }

    /**
     * 获取今日正在制作中的订单详情，workOrder为空
     *
     * @return
     */
    @Override
    public List<OrderDetailDO> listTodayInTheMakingWorkOrderIsNull() {
        return orderDetailMapper.listTodayInTheMakingWorkOrderIsNull();
    }

    /**
     * 获取今日的订单详情，workOrder为空
     *
     * @return
     */
    @Override
    public List<OrderDetailDTO> listTodayWorkOrderIsNull() {
        return orderDetailMapper.listTodayWorkOrderIsNull();
    }

    /**
     * 查询订单详情
     * @param orderDetailId
     * @return
     */
    @Override
    public OrderDetailDO findById(String orderDetailId) {
        return orderDetailMapper.findByOrderDetailId(orderDetailId);
    }

    /**
     * 修改订单状态
     * @param orderId
     * @param status
     */
    @Override
    public void editStatusByOrderId(String orderId, String status) {
        orderDetailMapper.editStatusByOrderId(orderId, status);
    }
}




